package cn.gson.crm;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import cn.gson.crm.interceptor.LoginInterceptor;
import cn.gson.crm.interceptor.RightsInterceptor;

@Configuration
@EnableWebMvc
public class AppMvcConfigurer extends WebMvcConfigurerAdapter {
	/**
	 * 视图解决方案配置
	 */
	@Override
	public void configureViewResolvers(ViewResolverRegistry registry) {
		//配置jsp路径
		registry.jsp("/WEB-INF/jsp/", ".jsp");
		super.configureViewResolvers(registry);
	}
	
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
		super.configureDefaultServletHandling(configurer);
	}
	
	/**
	 * 注册拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration loginIr=registry.addInterceptor(new LoginInterceptor());
		//拦截所有请求
		loginIr.addPathPatterns("/**");
		//排除登录请求
		loginIr.excludePathPatterns("/login");
		
		  //请求的权限过滤器
       /* InterceptorRegistration rightsRegistration = registry.addInterceptor(new RightsInterceptor());

        rightsRegistration.addPathPatterns("/**");
        rightsRegistration.excludePathPatterns("/", "/login", "/error", "/reject", "/menus","/index");*/
	}
}